﻿using System;
using System.Data;
using System.Xml.Linq;

namespace YArchitech.MEP
{
	public struct HYDuctSpecification : IComparable
	{
		public HYTubeSize Size { get; set; }

		public int Id { get; set; }

		public static implicit operator HYTubeSize(HYDuctSpecification spec)
		{
			return spec.Size;
		}

		public int CompareTo(object obj)
		{
			if (obj == null || !(obj is HYDuctSpecification))
			{
				return 1;
			}
			HYDuctSpecification hyductSpecification = (HYDuctSpecification)obj;
			return this.Size.CompareTo(hyductSpecification.Size);
		}

		public static HYDuctSpecification FromDataRow(DataRow dr)
		{
			HYDuctSpecification result = default(HYDuctSpecification);
			result.Id = Convert.ToInt32(dr["Id"]);
			HYTubeShape sp = (HYTubeShape)Convert.ToInt32(dr["Shape"]);
			double w = Convert.ToDouble(dr["Width"]);
			double h = Convert.ToDouble(dr["Height"]);
			result.Size = new HYTubeSize(sp, w, h);
			return result;
		}

		public static HYDuctSpecification FromDataReader(IDataReader reader)
		{
			HYDuctSpecification result = default(HYDuctSpecification);
			result.Id = Convert.ToInt32(reader["Id"]);
			HYTubeShape sp = (HYTubeShape)Convert.ToInt32(reader["Shape"]);
			double w = Convert.ToDouble(reader["Width"]);
			double h = Convert.ToDouble(reader["Height"]);
			result.Size = new HYTubeSize(sp, w, h);
			return result;
		}

		public void WriteXml(XElement xe)
		{
			xe.SetAttributeValue("Shape", (int)this.Size.Shape);
			xe.SetAttributeValue("Width", (int)this.Size.Width);
			xe.SetAttributeValue("Height", (int)this.Size.Height);
		}

		public void ReadXml(XElement xe)
		{
			int sp = (int)xe.Attribute("Shape");
			int num = (int)xe.Attribute("Width");
			int num2 = (int)xe.Attribute("Height");
			this.Size = new HYTubeSize((HYTubeShape)sp, (double)num, (double)num2);
		}
	}
}
